'use strict';

const Service = require('egg').Service;

class CodeService extends Service {
    async create(mobile, code) {
        const sql =
            'insert into code (mobile, code, create_time) values (?, ?, ?)';
        const parmas = [mobile, code, Date.now()];
        const res = await this.app.mysql.query(sql, parmas);
        return res;
    }

    async find(mobile) {
        const sql = 'select * from code where mobile = ? limit 0, 1';
        const parmas = [mobile];
        const res = await this.app.mysql.query(sql, parmas);
        return res[0];
    }

    async remove(mobile) {
        const sql = 'delete from code where mobile = ?';
        const parmas = [mobile];
        const res = await this.app.mysql.query(sql, parmas);
        return res;
    }
}

module.exports = CodeService;
